package com.renjun.smweb.controller.InterfaceController;

import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.annotation.AuthorityDeclaration;
import com.renjun.smweb.commons.util.ResponseUtils;
import com.renjun.smweb.service.InterfaceService.InterfaceService;
import com.renjun.smweb.annotation.AuthorityDeclaration;
import com.renjun.smweb.service.InterfaceService.InterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 接口管理
 * Created by 向立军 on 2017/4/5.
 */
@Controller
@RequestMapping("/interface")
public class InterfaceController {

    @Autowired
    private InterfaceService interfaceService;

    /**
     * 查询所有接口信息
     * @author  xlj
     * @param request
     * @param response
     * @return json
     */
    @ResponseBody
    @RequestMapping(value = "/queryInterfaceList",method = RequestMethod.POST)
    @AuthorityDeclaration(id = "M11-1", desc = "查询接口信息")
    public JSONObject queryInterfaceList(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject rs;
        try {
            rs = interfaceService.queryInterfaceList(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 修改接口状态
     * @author  xlj
     * @param request
     * @param response
     * @return json
     */
    @ResponseBody
    @RequestMapping(value = "/modifyInterface",method = RequestMethod.POST)
    @AuthorityDeclaration(id = "M11-2", desc = "修改接口状态")
    public JSONObject modifyInterface(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject rs;
        try {
            rs = interfaceService.modifyInterface(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }
}
